//
//  WKMineViewController.m
//  ourToken
//
//  Created by wakeup on 2018/5/29.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKMineViewController.h"
#import "WKBaseHeader.h"

@interface WKMineViewController ()<UITableViewDelegate, UITableViewDataSource, WKMineHeaderViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) WKMineHeaderView *headerView;
@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation WKMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationView];
    [self layoutUI];
    self.view.backgroundColor = [UIColor whiteColor];
    self.dataArray = @[
                       @[@"系统设置",@"安全中心",@"帮助中心",@"关于我们"],
                       @[@"she1",@"an1",@"bang1",@"guanyu1"]
                       ];
}

- (void)setNavigationView {
    [super setNavigationView];
    self.navigationView.topTitleLabel.text = @"我的";
    self.navigationView.topLeftButton.hidden = YES;
}

- (void)layoutUI {
    [self.view addSubview:self.tableView];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.headerView = [[[NSBundle mainBundle] loadNibNamed:@"WKMineHeaderView" owner:self options:nil] lastObject];
    self.headerView.frame = CGRectMake(0, 0, AppManager.width, 130*AppManager.scale);
    self.headerView.delegate = self;
    self.tableView.tableHeaderView = self.headerView;
}

#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.dataArray[0] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MineCell"];
    cell.textLabel.text = self.dataArray[0][indexPath.row];
    cell.textLabel.font = AppManager.tableTextFont;
    cell.imageView.image = [UIImage imageNamed:self.dataArray[1][indexPath.row]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        WKSetViewController *set = [[WKSetViewController alloc] init];
        [self.navigationController pushViewController:set animated:YES];
    }
    else if (indexPath.row == 1) {
        WKSecurityViewController *security = [[WKSecurityViewController alloc] init];
        [self.navigationController pushViewController:security animated:YES];
    }
    else if (indexPath.row == 2) {
        WKHelpViewController *help = [[WKHelpViewController alloc] init];
        [self.navigationController pushViewController:help animated:YES];
    }
    else if (indexPath.row == 3) {
        WKAboutViewController *about = [[WKAboutViewController alloc] init];
        [self.navigationController pushViewController:about animated:YES];
    }
}

#pragma mark - WKMineHeaderViewDelegate
//点击钱包按钮
- (void)clickWalletBtn {
    WKWalletManagerViewController *walletManager = [[WKWalletManagerViewController alloc] init];
    [self.navigationController pushViewController:walletManager animated:YES];
}

//点击地址按钮
- (void)clickAddressBtn {
    WKAddressViewController *address = [[WKAddressViewController alloc] init];
    [self.navigationController pushViewController:address animated:YES];
}

#pragma mark - 懒加载
- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, AppManager.navigationHeight, AppManager.width, AppManager.height-AppManager.navigationHeight-AppManager.tabBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc] init];
    }
    return _tableView;
}

@end
